package com.emperorque.mathpractice.model;

import java.util.Objects;

/**
 * 算术表达式模型类
 */
public class Expression {
    private final String expressionString;
    private final int result;
    private final ExpressionType type;

    /**
     * 构造函数
     * @param expressionString 表达式字符串（如："3 + 5"）
     * @param result 表达式的计算结果
     * @param type 表达式类型
     */
    public Expression(String expressionString, int result, ExpressionType type) {
        if (expressionString == null || expressionString.isEmpty()) {
            throw new IllegalArgumentException("表达式字符串不能为空");
        }
        if (type == null) {
            throw new IllegalArgumentException("表达式类型不能为空");
        }
        this.expressionString = expressionString;
        this.result = result;
        this.type = type;
    }

    /**
     * 获取表达式字符串
     */
    public String getExpressionString() {
        return expressionString;
    }

    /**
     * 获取计算结果
     */
    public int getResult() {
        return result;
    }

    /**
     * 获取表达式类型
     */
    public ExpressionType getType() {
        return type;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Expression that = (Expression) o;
        return Objects.equals(expressionString, that.expressionString);
    }

    @Override
    public int hashCode() {
        return Objects.hash(expressionString);
    }

    @Override
    public String toString() {
        return expressionString + " = " + result;
    }
}
